package com.timesheet.gui.efforttracker.views;
import org.eclipse.swt.*;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;

import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

public class Demo {

    public static void main (String [] args) {


        Display display = new Display ();
        Shell shell = new Shell (display);
        final Text txt;
        txt= new Text(shell, SWT.NONE);
        drawRedBorder(txt);

        txt.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent arg0) {
                // TODO Auto-generated method stub
                txt.getParent().redraw();

            }
        });


        shell.setLayout(new GridLayout());
        shell.open ();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }


        display.dispose ();
    }

    protected static void drawRedBorder(Control cont){
        final Control control = cont;

        cont.getParent().addPaintListener(new PaintListener(){
            public void paintControl(PaintEvent e){
               if(((Text) control).getText().length()<=0){
                    GC gc = e.gc;
                    Color red = new Color(null, 255, 0 ,0);
                    gc.setBackground(red);
                    Rectangle rect = control.getBounds();
                    Rectangle rect1 = new Rectangle(rect.x - 2, rect.y - 2,
                            rect.width + 1, rect.height + 1);
                    gc.setLineStyle(SWT.LINE_SOLID);
                    gc.fillRectangle(rect1);
               }
            }
        });
    }

} 